import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

export default class UserUpdatePasswordAction extends BaseAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.USER;
    this.name = "UserUpdatePasswordAction";
  }

  call(caller, data) {
    this._baseCall(caller, data);
    this.caller.setState({
      viewStatus: 4,
    })
  }

  finish(isSucceed,data,response) {
    var detail = "";
    if(isSucceed.user_id!==undefined||isSucceed.status == ResponseConstants.status_deal_success ||isSucceed.status == ResponseConstants.status_request_success) {
      detail = "修改成功";
    }
    else if (isSucceed.status == ResponseConstants.status_unauthorized) {
      detail = isSucceed.detail ? isSucceed.detail : "验证码过期或者不正确";
    }
    else if (isSucceed.status === ResponseConstants.status_server_error) {
      detail = "服务器出错";
    }
    else {
      detail = "未知错误";
    }
    detail=isSucceed.detail||detail;
    this.caller.setState({
      viewStatus: isSucceed.user_id!==undefined? 200: isSucceed.status,
      statusText: detail,
      updateSucess:true,
    })
  }
}
